package com.msb.user.controller;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author DreamAndLove
 * @date 2024/09/05 16:11
 * @description
 */
@RestController
public class UserProviderController {

    @Value("${server.port}")
    String port;

    private AtomicInteger count = new AtomicInteger();

    @GetMapping("/user")
    public JSONObject getUser() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", "zhangsan");
        jsonObject.put("birthday", "1990-01-01");
        jsonObject.put("address", "China");
        jsonObject.put("port", port);
        return jsonObject;
    }


    @GetMapping("/timeoutTest")
    public String timeoutTest() throws InterruptedException {
        System.out.println("准备睡，port is: " + port);
        Thread.sleep(500);
        int i = count.getAndIncrement();
        System.out.println("第 " + i + "次调用 port is: " + port);
        return "port: " + port;
    }

}
